//
//  TCLYRegisteredViewController.m
//  YuErmuYing
//
//  Created by LYang on 16/9/19.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYRegisteredViewController.h"
#import "TCLYRegisterView.h"
#import "TCLYBabyRegisterView.h"
#import "TCLYLoginViewController.h"
#import "TCLYLoginModel.h"
#import "Macros.h"
#import "Masonry.h"

@interface TCLYRegisteredViewController ()
@property (nonatomic, strong) TCLYLoginModel * loginModel;
@property (nonatomic, strong) TCLYBabyRegisterView * babyRegisterView;
@property (nonatomic, strong) TCLYRegisterView * promView;

@end

@implementation TCLYRegisteredViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(registeredLogin) name:@"registeredLogin" object:nil];
    self.loginModel = [[TCLYLoginModel alloc] init];
    self.promView = [[TCLYRegisterView alloc] init];
    [self createView];
}
-(void) createView{
    
    self.babyRegisterView = [[TCLYBabyRegisterView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
    UITapGestureRecognizer * textFeildTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
    [self.babyRegisterView addGestureRecognizer:textFeildTap];
    
    self.babyRegisterView.backgroundColor = bgColor;
    [self.babyRegisterView.loginBtn addTarget:self action:@selector(loginBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.babyRegisterView.registerBtn addTarget:self action:@selector(registerBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.babyRegisterView];
    
}
-(void)loginBtnAction{
    if (self.babyRegisterView.accountTextField.text.length != 11) {
        [self.promView prompt:@"你输入的账号有误" Controller:self];
        return;
    }
    if ([self.babyRegisterView.pwdTextField.text isEqual:self.babyRegisterView.againPwdTextField.text]) {
    }else{
        [self.promView prompt:@"两次输入的密码不一致" Controller:self];
        return;
    }
    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:self.babyRegisterView.accountTextField.text,@"phone",self.babyRegisterView.pwdTextField.text,@"pass",self.babyRegisterView.againPwdTextField.text,@"password", nil];
    [self.loginModel registeredLoginParameter:dic];
}
-(void)registeredLogin{
    if ([self.loginModel.loginStr isEqual:@400]) {
        [self.promView prompt:@"账户已存在" Controller:self];
        return;
    }
    [self.promView prompt:@"注册成功" Controller:self];
}
//隐藏键盘的方法
-(void)dismissKeyboard{
    [self.babyRegisterView.accountTextField resignFirstResponder];
    [self.babyRegisterView.pwdTextField resignFirstResponder];
    [self.babyRegisterView.againPwdTextField resignFirstResponder];
}
-(void)registerBtnAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
